#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>

pid_t pid[2];

void fun1(int);
void fun2(int);

int main(int argc, char **argv) {
  int i;
  for (i = 0; i < 2; i++) {
    pid[i] = fork();
    if (pid[i] == 0) {
      break;
    }
  }
  if (i == 2) {
    sleep(1);
    printf("I am father,my pid is %d\n", getpid());
    signal(3, fun1);
    pause();
    while (wait(NULL) != -1)
      ;
  }

  if (pid[1] == 0 || pid[0] == 0) {
    signal(2, fun2);
    pause();
  }
  return 0;
}

void fun1(int num) {
  // printf("This is father,catth %d\n",num);
  kill(pid[0], 2);
  kill(pid[1], 2);
}

void fun2(int num) {
  printf("I am child,my pid is %d\n", getpid());
  printf("This is child,killed by %d\n", num);
}
